import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";
const WidthRouter = (Cpn: any) => {
  const NewCpn: React.FC = () => {
    const navigate = useNavigate();
    const { pathname } = useLocation();
    useEffect(() => {
      const token = localStorage.getItem("token");
      if (!token && !["/login", "/sigin"].includes(pathname)) {
        navigate("/login");
      }
    }, [pathname]);

    return <Cpn />;
  };
  return NewCpn;
};
export default WidthRouter;
